function changeSyncTemplateStatus(id) {
	$.ajax({
		url:'changeSyncTemplateStatus.do',
		type:'POST',
		data:{'templateId':id},
		dataType:'json',
		success:function(data) {
			if (data.status) {
				//$(a).html('关闭');
				//$(a).parent().prev().html('开启');
			} else {
				//$(a).html('开启');
				//$(a).parent().prev().html('关闭');
			}
		},
		error:function() {
			alert('系统异常');
		}
	});
}

function exportTemplates(basePath) {
	var selects =$("input:checkbox[name='ids']:checked");
	if (selects.length < 1) {
		alert("请选择模板!");
		return;
	}
	
	var str = '';
	for(var i=0;i < document.getElementsByName('ids').length;i++)
	{
		  if(document.getElementsByName('ids')[i].checked){
		  	if(str=='') str += document.getElementsByName('ids')[i].value;
		  	else str += ',' + document.getElementsByName('ids')[i].value;
		  }
	}
	window.location.href = basePath + '/sync/exportTemplates.do?selects=' + str;
}

function deleteTemplates(basePath) {
	var selects =$("input:checkbox[name='ids']:checked");
	if (selects.length < 1) {
		alert("请选择模板!");
		return;
	}
	
	var str = '';
	for(var i=0;i < document.getElementsByName('ids').length;i++)
	{
		  if(document.getElementsByName('ids')[i].checked){
		  	if(str=='') str += document.getElementsByName('ids')[i].value;
		  	else str += ',' + document.getElementsByName('ids')[i].value;
		  }
	}
	
	$.ajax({
		url:'deleteTemplates.do',
		type:'POST',
		data:{'selects':str},
		dataType:'json',
		success:function(data) {
			if(data.success=="true"){
				alert("删除模板成功!");
			}else{
				alert("删除模板失败!");
			}
			window.location.href = basePath + '/sync/syncTemplateList.do';
		},
		error:function() {
			alert('系统异常');
		}
	});
	
}


function editTemplates(basePath,templateId) {
	var templateName = $("#temListForm").find('input[name="templateName"]').val();
	var userName = $("#temListForm").find('input[name="userName"]').val();
	var tableName = $("#temListForm").find('input[name="tableName"]').val();
	var dataSourceId = $("#temListForm").find('select[name="dataSourceId"]').val();
	var status = $("#temListForm").find('select[name="status"]').val();
	var sqlContent = $("#temListForm").find('textarea[name="sqlContent"]').val();

	
	var currentPage = $('font[color="#808080"]').text();
	var showCount= $(".pagination select option:eq(0)").val();

	
	window.location.href = basePath + '/sync/editSyncTemplate.do?templateId='+templateId+'&templateName='+templateName+'&userName='+userName+'&tableName='+tableName+'&dataSourceId='+dataSourceId+'&status='+status+'&sqlContent='+sqlContent+'&currentPage='+currentPage+'&showCount='+showCount;
}


function getManagerList(objectId,page2){
	var objectId;
	if (typeof(objectId) == "undefined"||''==objectId||null==objectId){
		 objectId= $("#objectId").val();
	}
	var objectType = 'SYNCTEMPLATE';

	
	$.ajax({
		url:'findSyncLog.do',
		type:'POST',
		data:{'page2':page2,'objectId':objectId,'objectType':objectType},
		dataType:'json',
		success:function(data) {
			$("#objectId").val(data.objectId);
	  		var comLogList=data.comLogList;
	  		var rs = "";
	  		if(comLogList.length==0){
	  			rs+= "<tr class='main_info'>";
	  			rs+= "<td colspan='10' class='center'>没有相关数据</td>";
	  			rs+="</tr>";
				$('#pagination').empty();
	  			$('#comlogs').empty();
		  		$('#comlogs').append(rs);
			  	$('#logModel').modal('show');

		  		return;
	  		}else{
	  			for (var i=0;i<comLogList.length;i++)
				{
					rs+="<tr>";
					rs+="<td>"+comLogList[i].memo+"</td>";
					rs+="<td><span style='font-weight:bold'>"+comLogList[i].operatorName+"</span></td>";
					rs+="<td>"+comLogList[i].content+"</td>";
					rs+="</tr>";
				}
	  			$('#comlogs').empty();
		  		$('#comlogs').append(rs);
	  		}
	  		
	  		var page2=data.page2;
	  		var pageCount2=data.pageCount2;
	  		var pagination = "";
	  		pagination+="<ul class='pagination pager_cus'>";
	  		pagination=pagination+"<li><a>第 "+(page2);
	  		pagination=pagination+" 页/共 "+(pageCount2)+" 页</a></li>";
	  		
	  		
	  		
	  		
	  		pagination += "<li><a href='javascript:getManagerList("+objectId+",";
			pagination += 0 + ");'>« 首页</a></li>";
	  		if(page2>0){
	  			pagination += "<li><a href='javascript:getManagerList("+objectId+",";
				pagination += (page2 - 1) + ");'>« 上一页</a></li>";
	  		}
	  		
	  		var start=page2-3;
	  		var end=page2+3;
	  		if(start<0){
	  			end=end-start;
	  		}
	  		if(end >(pageCount2-1)){
	  			end = pageCount2-1;
	  			start=end -7; 
	  		}
	  		for(var j=start;j<=end;j++){
	  			if(j>-1 && j<=pageCount2){
	  				if(page2==(j+1)){
	  					pagination += "<li  class='active'><a href='javascript:getManagerList("+objectId+",";
						pagination += (j+1) + ");'>"+(j+1)+"</a></li>";
	  				}else{
	  					pagination += "<li><a href='javascript:getManagerList("+objectId+",";
						pagination += (j+1) + ");'>"+(j+1)+"</a></li>";
	  				}
	  				
	  			}
	  		}
	  		
	  		if(page2<pageCount2-1){
	  			pagination += "<li><a href='javascript:getManagerList("+objectId+",";
				pagination += (page2 + 1) + ");'>下一页 »</a></li>";
	  		}
			pagination += "<li><a href='javascript:getManagerList("+objectId+",";
			pagination += (pageCount2) + ");'>« 尾页</a></li>";
					
			$('#pagination').empty();
	  		$('#pagination').append(pagination);

	  		
		  	$('#logModel').modal('show');
		},
		error:function() {
			alert('系统异常');
		}
	});
	
	
	}